package com.itrencai.d12_Recurtion.char_buffer;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

//目标：完成出师表的复制并恢复顺序
public class CopyCSB {
    public static void main(String[] args) throws IOException {

        try (//1.创建缓冲字符输入流与源文件接通
             BufferedReader br=new BufferedReader(new FileReader("E:\\javalearn\\opp-app\\oop-app\\src\\csb.txt"));
             //5.定义缓冲字符输出管道与目标文件接通
             BufferedWriter bw=new BufferedWriter(new FileWriter("E:\\javalearn\\opp-app\\oop-app\\src\\csbc.txt"));){

            //2.定义一个List集合存储每行内容
            List<String> data=new ArrayList<>();
            //3.定义循环按照行读取文章
            String  line;
            while ((line=br.readLine())!=null){
                data.add(line);
            }
            //System.out.println(data);
            //4.排序
            Collections.sort(data);
            System.out.println(data);

/*            //自定义排序规则
            List<String> sizes=new ArrayList<>();
            Collections.addAll(sizes,"一","二","三","四","五","六","七","八","九");
            Collections.sort(data, new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                   *//* return sizes.indexOf(o1.substring(0,o1.indexOf("\\.")))
                            -sizes.indexOf(o2.substring(0,o2.indexOf("\\.")));*//*
                    return sizes.indexOf("一")
                            -sizes.indexOf("九");
                }
            });
            System.out.println(data);*/


            //6.遍历集合中的每行文章写出去，要换行
            for (String datum : data) {
                bw.write(datum);
                bw.newLine();//换行
            }












        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
